﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace theRift
{
    public class GUI : Microsoft.Xna.Framework.DrawableGameComponent
    {
        protected SpriteBatch spriteBatch;
        protected GraphicsDeviceManager graphics;
        protected Texture2D dialog;
        protected Texture2D heart;
        protected Color dialogBoxColor;
        protected Player player;

        public Player Player
        {
            get { return player; }
            set { player = value; }
        }

        public GUI(Game game)
            : base(game)
        {
            this.spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            this.graphics = (GraphicsDeviceManager)Game.Services.GetService(typeof(IGraphicsDeviceManager));
            this.dialog = game.Content.Load<Texture2D>(Directories.TEXTURES_PATH + "dialog");
            this.heart = game.Content.Load<Texture2D>(Directories.TEXTURES_PATH + "heart");
            this.dialogBoxColor = new Color(0, 0, 0, 64);
        }

        public void DrawDialogBox(int width, int height, int top, int left)
        {
            spriteBatch.Draw(dialog, new Rectangle(left, top, width, height), dialogBoxColor);
        }

        public void DrawHealth()
        {
            for (int i = 0; i < player.CurHealth; i++)
            {
                spriteBatch.Draw(heart, new Rectangle(10 + (i * 22), 10, 26, 26), Color.White);
            }

            // Draw an indication for max health or not?
            /*for (int i = 0; i < (player.MaxHealth - player.CurHealth); i++)
            {
                spriteBatch.Draw(emptyHeart, new Vector2(10 + ((player.CurHealth + i) * 30), 10), Color.Red);
            }*/
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred,
                SaveStateMode.SaveState);
            DrawHealth();
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
